local dabian = fk.CreateSkill{
  name = "lingling__dabian",
}

Fk:loadTranslationTable{
  ["lingling__dabian"] = "大变",
  [":lingling__dabian"] = "准备阶段，你可以令所有角色各摸一张牌或各弃置一张手牌。",

  ["lingling__dabian-draw"] = "所有角色各摸一张牌",
  ["lingling__dabian-discard"] = "所有角色各弃置一张手牌",
}

dabian:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(dabian.name) and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local all_choices = { "lingling__dabian-draw", "lingling__dabian-discard", "Cancel" }
    local choices = table.simpleClone(all_choices)
    if not table.find(room.alive_players, function (p)
      return not p:isKongcheng()
    end) then
      table.remove(choices, 2)
    end
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = dabian.name,
      all_choices = all_choices,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice, tos = room:getAlivePlayers()})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead then
        if choice == "lingling__dabian-draw" then
          p:drawCards(1, dabian.name)
        else
          room:askToDiscard(p, {
            min_num = 1,
            max_num = 1,
            include_equip = false,
            skill_name = dabian.name,
            cancelable = false,
          })
        end
      end
    end
  end,
})

return dabian
